import * as QcloudSms from 'qcloudsms_js';
import * as crypto from 'crypto';

// 短信应用 SDK AppID
const appid = 1400225943;  // SDK AppID 以1400开头
// 短信应用 SDK AppKey
const appkey = "c77a3945af20b48e1014c6486ec0ba68";
// 短信模板 ID，需要在短信控制台中申请
const templateId = 7839;  // NOTE: 这里的模板ID`7839`只是示例，真实的模板 ID 需要在短信控制台中申请
// 签名
const smsSign = "西尼科技";  // NOTE: 签名参数使用的是`签名内容`，而不是`签名ID`。这里的签名"腾讯云"只是示例，真实的签名需要在短信控制台申请
// 实例化 QcloudSms
const qcloudsms = QcloudSms(appid, appkey);
var smsType = 0; // Enum{0: 普通短信, 1: 营销短信}
var ssender = qcloudsms.SmsSingleSender();

const ssenderOneCallback = function(err,res,resData){
    if(err){

    }
}
//商家注册成功单条短信发送
// export const ssenderOneOk = async params => {
//     // let random = await randomNum();
//     // let time = Date.now();
//     // const smsSign=crypto.createHmac('sha256',`appkey=${appkey}&random=${random}&time=${time}&mobile=${params.phoneNumbers}`);
//     return ssender.sendWithParam(86, params.phoneNumbers, 377838, [params.phoneNumbers,params.password], smsSign,"","",ssenderOneCallback)
// };
//商家注册单条短信发送
export const ssenderOneFail = async params => {
    return ssender.sendWithParam(86, params.phoneNumbers, 393217, [params.failureContents], smsSign,"","",ssenderOneCallback)
};

export const ssenderOneOk = async params => {
    return ssender.sendWithParam(86, params.phoneNumbers, 405072, [params.phoneNumbers,params.password,params.month,params.day], smsSign,"","",ssenderOneCallback)
};

//商家短信验证登入
export const ssenderBusinessLogin = async params => {
    return ssender.sendWithParam(86, params.phoneNumbers, 377840, [params.code], smsSign,"","",ssenderOneCallback)
};

//商家银行卡短信
export const ssenderBusinessBank = async params => {
    return ssender.sendWithParam(86, params.phoneNumbers, 368011, [params.bankName,params.bankCode,params.code], smsSign,"","",ssenderOneCallback)
};

//商家绑定短信
export const ssenderBindBusiness = async params => {
    return ssender.sendWithParam(86, params.phoneNumbers, 449126, [params.code], smsSign,"","",ssenderOneCallback)
};

export const randomNum:any = function(){ 
    var Num=""; 
    for(var i=0;i<6;i++) 
    {
        Num+=Math.floor(Math.random()*10); 
    }
    return Num;
}